﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using yiCommerce.Areas.Admin.Models.Shops;
using yiCommerce.Attributes;
using yiCommerce.Service.Customers;
using yiCommerce.Service.Shops;

namespace yiCommerce.Areas.Admin.Controllers
{
    [AdminAuthorize]
    [AdminShopAuthorize] 
    public class ShopController : Controller
    {
        private IShopService _shopService;


        private ICustomerService _customerService;

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult AssignShopOwner(int shopId)
        {
            var model = new AssignShopOwnerModel()
                {
                    ShopId = shopId,
                    AvailableShopOwners = BuildAvailableShopOwners()
                };
            ViewBag.Model = model;
            return View();
        }


        private IList<ShopOwnerModel> BuildAvailableShopOwners()
        {
            var result = new List<ShopOwnerModel>();
            var customers = _customerService.GetAllNotUsedShopOwners();
            if (customers != null)
            {
                
            result = customers.Select(c => new ShopOwnerModel()
                {
                    Email = c.Email,
                    Name = c.Username,
                    ShopOwnerId = c.Id
                }).ToList();
            }

            return result;

        }

        public ActionResult List()
        {

            var shops = _shopService.GetAllShops();
            var shopListModel = new ShopListModel();

            if (shops != null)
            {

                shopListModel.Shops = shops.Select(c => new ShopEditModel()
                    {
                        ShopName = c.ShopName
                    }).ToList();
                
            }
            ViewBag.Model = shopListModel;
            return View();

        }

        public ActionResult Create()
        {
            return View();
        }

    }
}
